package day01;

/**
 * @author feng
 * @Date 2021/10/14 9:12
 * 饿汉式(静态代码块)
 */
class Singleton02 {
    public static void main(String[] args) {

        Singleton01 instance = Singleton01.getInstance();
        System.out.println(instance);
    }

}

class Singleton01{

    private Singleton01(){}
    //声明实例
   private static Singleton01 singleton;

    static {
        singleton = new Singleton01();
    }

    //提供静态对外的方法，返回实例
    public static Singleton01 getInstance(){
        return singleton;
    }


}